package cn.darkfire.CarWeb.Service.impl;

import cn.darkfire.CarWeb.Dao.CarDao;
import cn.darkfire.CarWeb.POJO.Car;
import cn.darkfire.CarWeb.Service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("carService")
public class CarServiceImpl implements CarService {

    @Autowired
    private CarDao carDao;

    @Override
    public List<Car> getAllCar() {
        return carDao.selectAllCar();
    }

    @Override
    public List<Car> searchCar(String name) {
        return carDao.searchCar(name);
    }

    @Override
    public Car queryCarByName(String name) {
        return null;
    }

    @Override
    public int deleteCar(String id) {
        return carDao.del(id);
    }

    @Override
    public int addCar(Car car) {
        return carDao.insert(car);
    }

    @Override
    public boolean carIsExist(String id) {
        Car car = new Car();
        car.setCarID(id);
        car.setCarName("");
        car.setCarPrice("0");
        car.setCarPrice("");
        if(addCar(car) == 0){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateCar(Car car) {
        if(carDao.update(car) > 0){
            return true;
        }
        return false;
    }

    @Override
    public int getID() {
        return carDao.getID();
    }
}
